package day0326;

import java.util.Arrays;
import java.util.Scanner;

public class Test10 {
    public static void main(String[] args) {
        String []  answers=generateQuestionAndAnswer(3,2);
        System.out.println(Arrays.toString(answers));
    }
    //                                 3                2
    public static String[] generateQuestionAndAnswer(int  questionCount,  int  stuCount) {
        String[]  qAa=new String[questionCount*stuCount];
        int index=0;
        //1.用for循环执行三次，表示三个老师分别出三道题
        Scanner s=new Scanner(System.in);
        for (int i = 0; i < questionCount ; i++) {
            int n1 = (int) (Math.random() * 50 + 1);
            int n2 = (int) (Math.random() * 50 + 1);
            int ope = (int) (Math.random() * 4 + 1);  //[1, 5)
            //用switch根据一个随机数的值，来生成加减乘除的一种题

            //2.再包含一个内循环执行两次，用来表示两个学生都回答这道题。
            for (int j = 0; j < stuCount; j++) {
                //2.1.得先用switch判断生成的是加减乘除哪种题。
                System.out.println("请第" + (j+1) + "个学生作答：");
                switch (ope) {
                    case 1:System.out.println(n1 + "+" + n2 + "=");break;
                    case 2: System.out.println(n1 + "-" + n2 + "=");break;
                    case 3: System.out.println(n1 + "*" + n2 + "=");break;
                    case 4: System.out.println(n1 + "/" + n2 + "=");break;
                }
                int answer = s.nextInt();
                switch (ope) {
                    case 1:    qAa[index] = (   n1 + "+" + n2 + "="+ answer +     (answer == (n1 + n2) ?   "-回答正确"    :    "-回答错误")   ); break;
                    case 2:    qAa[index] = (   n1 + "-" + n2 + "="+ answer +     (answer == (n1 - n2) ?   "-回答正确"    :    "-回答错误")   ); break;
                    case 3:    qAa[index] = (   n1 + "*" + n2 + "="+ answer +     (answer == (n1 * n2) ?   "-回答正确"    :    "-回答错误")   );break;
                    case 4:    qAa[index] = (   n1 + "/" + n2 + "="+ answer +     (answer == (n1 / n2) ?   "-回答正确"    :    "-回答错误")   ); break;
                }
                index++;
                // 2.2.用三目运算符判断对错。
            }
        }
        return qAa;
    }
}
